/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Javabank;

import Connection.Connector;
import Models.Account;
import Models.Transactie;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;

/**
 *
 * @author Luuk
 */
@WebService(serviceName = "JavabankWebService")
public class JavabankWebService {
    
    private Connector connector = new Connector();
    /**
     * Web service operation
     */
    @WebMethod(operationName = "openAccount")
    public void openAccount(@WebParam(name = "account") Account account) {
        connector.saveAccount(account);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "transfer")
    public boolean transfer(@WebParam(name = "amount") float amount, @WebParam(name = "reknummerFrom") int reknummerFrom, @WebParam(name = "reknummerTo") int reknummerTo) {
        return connector.transfer(amount, reknummerFrom, reknummerTo);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "getAccount")
    public Account getAccount(@WebParam(name = "reknummer") int reknummer) {
        try {
            return connector.getAccount(reknummer);
        } catch (Exception ex) {
            Logger.getLogger(JavabankWebService.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "alterAccount")
    public void alterAccount(@WebParam(name = "account") Account account) {
        connector.alterAccount(account);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "getTransactions")
    public Models.Transactie[] getTransactions(@WebParam(name = "reknummer") int reknummer, @WebParam(name = "date") String date) {
        return connector.getTransactions(reknummer, date);
    }
}
